package main

import (
	"fmt"
	"sync"
	"time"
)

//将练习1.2中的生产者消费者模型修改成为多个生产者和多个消费者模式

func main(){
	intChannel := make(chan int,10)
	var wg sync.WaitGroup
	for i := 0; i <= 10; i++ {
		wg.Add(1)
		go func(i int){
			defer wg.Done()
			for{
				intChannel<- i
				fmt.Printf("[producer%d] put: %d\n",i,i)
				time.Sleep(1 * time.Second)
			}
		}(i)
	}
	for i := 0; i <= 10; i++ {
		wg.Add(1)
		go func(name int){
			defer wg.Done()
			for{
				i:= <-intChannel 
				fmt.Printf("[consumer%d] get: %d\n",name,i)
				time.Sleep(1 * time.Second)
			}
		}(i)
	}
	wg.Wait()
}

